package com.fivefu.core.hik.controller;

import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.services.RegionServices;
import com.fivefu.core.hik.vo.RegionsTimeRangeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * <p>
 * 海康区域信息表 前端控制器
 * </p>
 *
 * @author 
 * @since 2022-06-30 14:07:20
 */
@Api(tags = "区域")
@RestController
@RequestMapping("/hikRegions")
public class DbHikRegionsController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(DbHikRegionsController.class);

    @Resource
    private RegionServices regionServices;

    @ApiOperation(value = "获取根区域信息", httpMethod = "POST", response = ResultInfo.class, notes = "获取根区域信息")
    @RequestMapping(path = "/queryHikRegionsRoot", method = RequestMethod.POST)
    public ResultInfo queryHikRegionsRoot(){
        try {
            regionServices.queryRegionsRoot();
            return ResultInfo.renderSuccess("获取根区域信息成功");
        } catch (Exception e) {
            logger.error("根区域信息出现异常" + e.getMessage(), e);
            return ResultInfo.renderError("获取根区域信息失败");
        }
    }

    @ApiOperation(value = "查询海康区域列表v2",httpMethod = "POST",response = ResultInfo.class,notes = "查询海康区域列表v2")
    @RequestMapping(path = "/queryHikRegionsList",method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resourceType",value = "资源类型(region:区域)",paramType = "query",required = true,dataType = "String")
    })
    public ResultInfo queryHikRegionsList() {
        try {
            String resourceType = StrUtils.isCheckNull(request.getParameter("resourceType"));
            if (StrUtils.isNull(resourceType)){
                return ResultInfo.renderError("资源类型不能为空");
            }
            regionServices.queryHikRegionsList(resourceType);
            return ResultInfo.renderSuccess("查询海康区域列表v2成功");
        } catch (Exception e) {
            logger.error("查询海康区域列表v2出现异常"+e.getMessage(),e);
            return ResultInfo.renderError("查询海康区域列表v2失败");
        }
    }

    @ApiOperation(value = "根据区域编号获取下一级区域列表v2",httpMethod = "POST",response = ResultInfo.class,notes = "根据区域编号获取下一级区域列表v2")
    @RequestMapping(path = "/queryHikSubRegionsList",method = RequestMethod.POST)
    public ResultInfo queryHikSubRegionsList() {
        try {
            regionServices.queryHikSubRegionsList();
            return ResultInfo.renderSuccess("根据区域编号获取下一级区域列表v2成功");
        } catch (Exception e) {
            logger.error("根据区域编号获取下一级区域列表v2出现异常"+e.getMessage(),e);
            return ResultInfo.renderError("根据区域编号获取下一级区域列表v2失败");
        }
    }

    @ApiOperation(value = "分页获取区域列表", httpMethod = "POST", response = ResultInfo.class, notes = "分页获取区域列表")
    @RequestMapping(path = "/queryHikRegionsByPage", method = RequestMethod.POST)
    public ResultInfo queryHikRegionsByPage(){
        try {
            regionServices.queryHikRegionsByPage();
            return ResultInfo.renderSuccess("分页获取区域列表成功");
        } catch (Exception e) {
            logger.error("分页获取区域列表出现异常" + e.getMessage(), e);
            return ResultInfo.renderError("分页获取区域列表失败");
        }
    }

    @ApiOperation(value = "根据编号获取区域详细信息", httpMethod = "POST", response = ResultInfo.class, notes = "根据编号获取区域详细信息")
    @RequestMapping(path = "/queryHikRegionsDetail", method = RequestMethod.POST)
    public ResultInfo queryHikRegionsDetail(){
        try {
            regionServices.queryHikRegionsDetail();
            return ResultInfo.renderSuccess("根据编号获取区域详细信息成功");
        } catch (Exception e) {
            logger.error("根据编号获取区域详细信息出现异常" + e.getMessage(), e);
            return ResultInfo.renderError("根据编号获取区域详细信息失败");
        }
    }

    @ApiOperation(value = "增量获取区域数据", httpMethod = "POST", response = ResultInfo.class, notes = "增量获取区域数据")
    @RequestMapping(path = "/queryHikRegionsTimeRange", method = RequestMethod.POST)
    public ResultInfo queryHikRegionsTimeRange(@ModelAttribute @Valid RegionsTimeRangeVo regionsTimeRangeVo){
        try {
            String startTime = regionsTimeRangeVo.getStartTime();
            Integer pageNo = regionsTimeRangeVo.getPageNo();
            Integer pageSize = regionsTimeRangeVo.getPageSize();
            if (StrUtils.isNull(startTime)){
                return ResultInfo.renderError("开始时间不能为空");
            }
            if (pageNo==null){
                return ResultInfo.renderError("当前页不能为空");
            }
            if (pageSize==null){
                return ResultInfo.renderError("每页显示条数不能为空");
            }
            regionServices.queryHikRegionsTimeRange(regionsTimeRangeVo);
            return ResultInfo.renderSuccess("增量获取区域数据成功");
        } catch (Exception e) {
            logger.error("增量获取区域数据出现异常" + e.getMessage(), e);
            return ResultInfo.renderError("增量获取区域数据失败");
        }
    }
}
